package org.rambadger.command.event;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import org.rambadger.command.validation.UrlIdentifier;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * Event representing the creation of an {@link org.rambadger.command.model.AssignmentEntity Assignment} under {@link org.rambadger.command.model.PlatformAggregate Platform}
 */
public class AssignmentCreated implements Serializable {
    private static final long serialVersionUID = -5759735099982458631L;

    //Compound Key {
    private final String platformId;
    private final String assignmentId;
    //}
    private final String assignmentName;
    private final String description;

    private final int submissionPoints;
    private final int reviewPoints;

    /**
     * Instantiates a new event.
     *
     * @param platformId the platform id
     * @param assignmentId the per platform unique identifier for the assignment
     * @param assignmentName assignment name/title
     * @param description the description
     * @param submissionPoints the maximum number of submission point a reviewer may award a user for this assignment
     * @param reviewPoints how many review points a reviewer receives for completing a review of a submission for this assignment
     */
    public AssignmentCreated(String platformId, String assignmentId, String assignmentName, String description, int submissionPoints, int reviewPoints) {
        this.platformId = platformId;
        this.assignmentId = assignmentId;
        this.assignmentName = assignmentName;
        this.description = description;
        this.submissionPoints = submissionPoints;
        this.reviewPoints = reviewPoints;
    }

    /**
     * Gets the identifier for the platform.
     *
     * @return the platform id
     */
    @UrlIdentifier @NotNull
    public String getPlatformId() {
        return platformId;
    }

    /**
     * Gets the per platform unique identifer for the assignment being created.
     *
     * @return the assignment id
     */
    @UrlIdentifier @NotNull
    public String getAssignmentId() {
        return assignmentId;
    }

    /**
     * Gets assignment name/display title.
     *
     * @return the assignment name
     */
    @Length(max = 64) @NotBlank
    public String getAssignmentName() {
        return assignmentName;
    }

    /**
     * Gets description.
     *
     * @return the description
     */
    @Length(max = 4096) @NotBlank
    public String getDescription() {
        return description;
    }

    /**
     * Gets the maximum number of submission points that may be awarded to a user for completing the assignment.
     *
     * @return the maximum submission points awardable.
     */
    @Min(0)
    public int getSubmissionPoints() {
        return submissionPoints;
    }

    /**
     * Gets the number review points awarded to a reviewer for completing a review of this assignment.
     *
     * @return the review points awarded
     */
    @Min(0)
    public int getReviewPoints() {
        return reviewPoints;
    }

    public String getFullAssignmentId() {
        return platformId+"/"+assignmentId;
    }

    @Override
    public String toString() {
        return "AssignmentCreated{" +
                "platformId='" + platformId + '\'' +
                ", assignmentId='" + assignmentId + '\'' +
                ", assignmentName='" + assignmentName + '\'' +
                ", description='" + description + '\'' +
                ", submissionPoints=" + submissionPoints +
                ", reviewPoints=" + reviewPoints +
                '}';
    }
}